﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MauiApp1
{
    public partial class MainPageViewModel: ObservableObject
    {
        public ObservableCollection<Item> YourItemsSource { get; set; }

        public MainPageViewModel()
        {
            YourItemsSource = new ObservableCollection<Item>
            {
                new Item { Name = "张三1", Age = 30, City = "北京" },
                new Item { Name = "李四2", Age = 22, City = "上海" },
                new Item { Name = "王五3", Age = 28, City = "广州" },
                new Item { Name = "张三4", Age = 30, City = "北京" },
                new Item { Name = "李四5", Age = 22, City = "上海" },
                new Item { Name = "张三6", Age = 30, City = "北京" },
                new Item { Name = "李四7", Age = 22, City = "上海" },
                new Item { Name = "张三8", Age = 30, City = "北京" },
                new Item { Name = "李四9", Age = 22, City = "上海" },
                new Item { Name = "张三10", Age = 30, City = "北京" },
                new Item { Name = "李四11", Age = 22, City = "上海" },
                new Item { Name = "张三12", Age = 30, City = "北京" },
                new Item { Name = "李四13", Age = 22, City = "上海" },
                new Item { Name = "张三14", Age = 30, City = "北京" },
                new Item { Name = "李四15", Age = 22, City = "上海" },
                new Item { Name = "王五16", Age = 28, City = "广州" },
                new Item { Name = "张三17", Age = 30, City = "北京" },
                new Item { Name = "李四18", Age = 22, City = "上海" },
                new Item { Name = "张三19", Age = 30, City = "北京" },
                new Item { Name = "李四20", Age = 22, City = "上海" },
                new Item { Name = "张三21", Age = 30, City = "北京" },
                new Item { Name = "李四22", Age = 22, City = "上海" },
                new Item { Name = "张三23", Age = 30, City = "北京" },
                new Item { Name = "李四24", Age = 22, City = "上海" },
                new Item { Name = "张三25", Age = 30, City = "北京" },
                new Item { Name = "李四26", Age = 22, City = "上海" },
                new Item { Name = "张三27", Age = 30, City = "北京" },
                new Item { Name = "李四28", Age = 22, City = "上海" },
                new Item { Name = "王五29", Age = 28, City = "广州" },
                new Item { Name = "张三30", Age = 30, City = "北京" },
                new Item { Name = "李四31", Age = 22, City = "上海" },
                new Item { Name = "张三32", Age = 30, City = "北京" },
                new Item { Name = "李四33", Age = 22, City = "上海" },
                new Item { Name = "张三34", Age = 30, City = "北京" },
                new Item { Name = "李四35", Age = 22, City = "上海" },
                new Item { Name = "张三36", Age = 30, City = "北京" },
                new Item { Name = "李四37", Age = 22, City = "上海" },
                new Item { Name = "张三38", Age = 30, City = "北京" },
                new Item { Name = "李四39", Age = 22, City = "上海" }
             };
        }        

        [RelayCommand]
        private void ClickItem(Item item)
        {
            item.Age = 100;
        }

        public Func<Item, Task<bool>> AddFunc { get => SubmitAddItem; }
        
        private async Task<bool> SubmitAddItem(Item? item)
        {
            await Task.Delay(8000);
            return true;
        }

        public Func<Item, Task<bool>> EditFunc { get => SubmitEditItem; }

        public async Task<bool> SubmitEditItem(Item? item)
        {
            await Task.Delay(8000);
            return true;
        }
    }
}
